package cn.tedu.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TheadPoolDemo01 {
    public static void main(String[] args) {

        ExecutorService executorService =
                //创建只有一个线程池的线程池
                //Executors.newSingleThreadExecutor();
                //创建最多只有两个线程的线程的线程池
                Executors.newFixedThreadPool(2);
                //创建线程数量没有上限的线程池(上限是整数的最大值)
                //Executors.newCachedThreadPool();
        for (int i = 0; i < 5; i++){
            executorService.execute(()->{
                String threadName = Thread.currentThread().getName();
                System.out.println(threadName+"->"+System.currentTimeMillis());
            });
        }
        //关闭线程池
        executorService.shutdown();
    }
}
